function rollDice( intDice , strAdder ) {
	if ( typeof strAdder == "undefined" ) {
		var roll_adder = "nil";
		} else {
		var roll_adder = strAdder;
		}
	
	var arr_dice = new Array();
	var result = new Array();
	var effect = 0;
	var body = 0;
	for ( ii=0 ; ii<intDice ; ii++ ) {
		var die_roll = Math.floor(Math.random() * (6)) + 1;
		arr_dice.push( die_roll );
		effect += die_roll;
		switch ( die_roll ) {
			case 2:
			case 3:
			case 4:
			case 5:
				body += 1;
				break;
			case 6:
				body += 2;
				break;
			}
		}

	switch( roll_adder ) {
		case "pip":
			effect += 1;
			result['pip'] = 1;
			break;
		case "half":
			half_die = Math.floor(Math.random() * (6)) + 1;
			switch ( half_die ) {
				case 1:
				case 2:
					effect += 1;
					break;
				case 3:
					effect += 2;
					break;
				case 4:
					effect += 2;
					body += 1;
					break;
				case 5:
				case 6:
					effect += 3;
					body += 1;
					break;
				}
			result['half_die'] = half_die;
			break;
		case "minus_one":
			var minus_one = ( Math.floor( Math.random() * ( 6 ) ) + 1 );
			result['minus_one'] = ( minus_one );
			minus_one--;
			if ( minus_one == 0 ) { minus_one = 1; }
			effect += minus_one;
			switch ( minus_one ) {
				case 2:
				case 3:
				case 4:
				case 5:
					body += 1;
					break;
				}
			break;
		}
	
	result['dice'] = arr_dice;
	result['effect'] = effect;
	result['body'] = body;
	
	return result;

	}


function logDieRoll( intDice , strAdder ) {
	if ( typeof intDice == "undefined" ) {
		var dice = parseInt( document.getElementById("countDSix").value );
		} else {
		var dice = intDice;
		}
	if ( typeof strAdder == "undefined" ) {
		var roll_adder = getCheckedValue( document.forms['die_roll_adder_form'].elements['die_roll_adder'] );
		} else {
		var roll_adder = strAdder;
		}
	var result = rollDice( dice , roll_adder );
	var response = "Rolled <span class=\"bold\">";
	switch( roll_adder ) {
		case "pip":
			response += dice + "d6+1";
			break;
		case "half":
			response += dice + " 1/2d6";
			break;
		case "minus_one":
			response += (dice +1 ) + "d6-1";
			break;
		case "nil":
		default:
			response += dice + "d6";
			break;
		}
	response += "</span>: " + result['effect'] + " Effect / " + result['body'] + " BODY";
	response += printDiePool( result );
	
	var active_entry_id = combatLogFindActive();
	if( active_entry_id !== false ) {
		combatLogAppend( active_entry_id , response );
		} else {
		combatLogEntry( response );
		}
	}

function logStunXRoll() {
	var result = rollDice( 0, "minus_one" );

	var response = "STUN Multiplier: <span class=\"bold\">" + ( result['effect'] ) + "</span>";
	response += printDiePool( result );
	
	var active_entry_id = combatLogFindActive();
	if( active_entry_id !== false ) {
		combatLogAppend( active_entry_id , response );
		} else {
		combatLogEntry( response );
		}
	}

function logArmorActivation() {
	var result = rollDice( 3, "nil" );

	var response = "Armor Activation: <span class=\"bold\">" + ( result['effect'] ) + "-</span>";
	response += printDiePool( result );
	
	var active_entry_id = combatLogFindActive();
	if( active_entry_id !== false ) {
		combatLogAppend( active_entry_id , response );
		} else {
		combatLogEntry( response );
		}
	}

function attackRoll() {
	var result = new Array();
	var attack = new Array();
	var location = new Array();

	attack_dice = rollDice( 3 , "nil");
	unadjustedAttack = 11 - attack_dice.effect;
	attack['unadjusted'] = unadjustedAttack;
	attack['dice'] = attack_dice;
	
	location = hitLocationRoll();

	result['attack'] = attack;
	result['location'] = location;	
	return result;
	}

function characteristicRoll( value ) {
	var roll = Math.round( (parseInt( value ) / 5 ) + 9 );
	var threeD6 = rollDice( 3 , "nil" ).effect;
	var result = roll - threeD6;
	return result;
	}

function hitLocationRoll() {
	var location_dice = rollDice( 3 , "nil" );
	var result = new Array();
	switch ( location_dice.effect ) {
		case 3:
		case 4:
		case 5:
			result['location'] = "head";
			result['BODYx'] = 2;
			result['nSTUNx'] = 2;
			result['kSTUNx'] = 5;
			break;
		case 6:
			result['location'] = "hand";
			result['BODYx'] = 0.5;
			result['nSTUNx'] = 0.5;
			result['kSTUNx'] = 1;
			break;
		case 7:
		case 8:
			result['location'] = "arm";
			result['BODYx'] = 0.5;
			result['nSTUNx'] = 0.5;
			result['kSTUNx'] = 2;
			break;
		case 9:
			result['location'] = "shoulder";
			result['BODYx'] = 1;
			result['nSTUNx'] = 1;
			result['kSTUNx'] = 3;
			break;
		case 10:
		case 11:
			result['location'] = "chest";
			result['BODYx'] = 1;
			result['nSTUNx'] = 1;
			result['kSTUNx'] = 3;
			break;
		case 12:
			result['location'] = "belly";
			result['BODYx'] = 1;
			result['nSTUNx'] = 1.5;
			result['kSTUNx'] = 4;
			break;
		case 13:
			result['location'] = "vitals";
			result['BODYx'] = 2;
			result['nSTUNx'] = 1.5;
			result['kSTUNx'] = 4;
			break;
		case 14:
			result['location'] = "thigh";
			result['BODYx'] = 1;
			result['nSTUNx'] = 1;
			result['kSTUNx'] = 2;
			break;
		case 15:
		case 16:
			result['location'] = "leg";
			result['BODYx'] = 0.5;
			result['nSTUNx'] = 0.5;
			result['kSTUNx'] = 2;
			break;
		case 17:
		case 18:
			result['location'] = "foot";
			result['BODYx'] = 0.5;
			result['nSTUNx'] = 0.5;
			result['kSTUNx'] = 1;
			break;
		}
	result['dice'] = location_dice;
	return result;
	}